using UnityEngine;

public class SceneGame_Character : MonoBehaviour
{
	
	public  float     InvencibleTime   = 0.0f;
	public  AudioClip DeathSound;
	public  int       MaxHealth        = 1;
    public  int       Health;
	private float     _InvencibleTimer;
	
	public void Start()
	{
		Health = MaxHealth;
	}
	
	public void Update()
	{
		float smoothDeltaTime = Mathf.Clamp(Time.smoothDeltaTime, 0.01666667f, float.MaxValue);
		if (_InvencibleTimer > 0.0f)
		{
			_InvencibleTimer = Mathf.Clamp(_InvencibleTimer - smoothDeltaTime, 0.0f, float.MaxValue);
			renderer.enabled = (Mathf.FloorToInt(60.0f * _InvencibleTimer) % 2) == 0;
		}
	}
	
	public void OnTriggerEnter(Collider collider)
	{
		if ((collider.name == "Wall") || (_InvencibleTimer > 0.0f))
			return;
		--Health;
		if (Health <= 0)
		{
			if (audio && DeathSound)
				audio.PlayOneShot(DeathSound);
			if (gameObject.name == "PlayerPrefab")
			{
				gameObject.renderer.enabled = false;
				SceneGame.Instance.Step     = 2;
			}
			else
				Destroy(gameObject);
		}
		else
			_InvencibleTimer = InvencibleTime;
	}
	
}